package com.nt.train.config;

import com.nt.train.beanlife.MyBeanLifeService;
import com.nt.train.service.IMyBeanService;
import com.nt.train.service.impl.MyBeanMatchServiceImpl;
import com.nt.train.service.impl.MyBeanServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * @author hlf
 * @version 1.0
 * @date 2022/9/28 21:01
 */
@Configuration
public class MyBeanConfig {

    @Bean
    @Profile("dev")
    public IMyBeanService myyBeanService(){
        IMyBeanService myBeanDev = new MyBeanServiceImpl();
        myBeanDev.hello();
        return myBeanDev;
    }

    @Bean
    @ConditionalOnProperty(name = {"mybean.ok"}, havingValue = "ok", matchIfMissing = false)
    public IMyBeanService myBeanOK() {
        IMyBeanService myBeanOk = new MyBeanMatchServiceImpl();
        myBeanOk.hello();
        return myBeanOk;
    }

//    @Bean
//    public MyBeanLifeService myBeanLifeService(){
//        MyBeanLifeService myBeanLifeService = new MyBeanLifeService();
//        myBeanLifeService.setName("myBeanLifeService_007");
//        return myBeanLifeService;
//    }

}
